package com.xydtech.ecard.config.controller;

import com.xydtech.common.annotation.Log;
import com.xydtech.common.core.controller.BaseController;
import com.xydtech.common.core.domain.AjaxResult;
import com.xydtech.common.core.page.TableDataInfo;
import com.xydtech.common.enums.BusinessType;
import com.xydtech.common.utils.poi.ExcelUtil;
import com.xydtech.ecard.config.domain.EcardServeModuleFunction;
import com.xydtech.ecard.config.service.IEcardServeModuleFunctionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 服务模块功能配置Controller
 *
 * @author JHON
 * @date 2022-06-23
 */
@Controller
@RequestMapping("/ecard/config/serveModuleFunction")
public class EcardServeModuleFunctionController extends BaseController {
    private String prefix = "ecard/config/serveModuleFunction";

    @Autowired
    private IEcardServeModuleFunctionService ecardServeModuleFunctionService;

    @RequiresPermissions("ecard:config:serveModuleFunction:view")
    @GetMapping("/{moduleId}")
    public String serveModuleFunction(@PathVariable("moduleId") Long moduleId, ModelMap mmap) {
        mmap.put("moduleId", moduleId);
        return prefix + "/serveModuleFunction";
    }

    /**
     * 查询服务模块功能配置列表
     */
    @RequiresPermissions("ecard:config:serveModuleFunction:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EcardServeModuleFunction ecardServeModuleFunction) {
        startPage();
        List<EcardServeModuleFunction> list = ecardServeModuleFunctionService.selectEcardServeModuleFunctionList(ecardServeModuleFunction);
        return getDataTable(list);
    }

    /**
     * 导出服务模块功能配置列表
     */
    @RequiresPermissions("ecard:config:serveModuleFunction:export")
    @Log(title = "服务模块功能配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EcardServeModuleFunction ecardServeModuleFunction) {
        List<EcardServeModuleFunction> list = ecardServeModuleFunctionService.selectEcardServeModuleFunctionList(ecardServeModuleFunction);
        ExcelUtil<EcardServeModuleFunction> util = new ExcelUtil<EcardServeModuleFunction>(EcardServeModuleFunction.class);
        return util.exportExcel(list, "服务模块功能配置数据");
    }

    /**
     * 新增服务模块功能配置
     */
    @GetMapping("/add/{moduleId}")
    public String add(@PathVariable("moduleId") Long moduleId, ModelMap mmap) {
        mmap.put("moduleId", moduleId);
        return prefix + "/add";
    }

    /**
     * 新增保存服务模块功能配置
     */
    @RequiresPermissions("ecard:config:serveModuleFunction:add")
    @Log(title = "服务模块功能配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EcardServeModuleFunction ecardServeModuleFunction) {
        return toAjax(ecardServeModuleFunctionService.insertEcardServeModuleFunction(ecardServeModuleFunction));
    }

    /**
     * 修改服务模块功能配置
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        EcardServeModuleFunction ecardServeModuleFunction = ecardServeModuleFunctionService.selectEcardServeModuleFunctionById(id);
        mmap.put("ecardServeModuleFunction", ecardServeModuleFunction);
        return prefix + "/edit";
    }

    /**
     * 修改保存服务模块功能配置
     */
    @RequiresPermissions("ecard:config:serveModuleFunction:edit")
    @Log(title = "服务模块功能配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EcardServeModuleFunction ecardServeModuleFunction) {
        return toAjax(ecardServeModuleFunctionService.updateEcardServeModuleFunction(ecardServeModuleFunction));
    }

    /**
     * 删除服务模块功能配置
     */
    @RequiresPermissions("ecard:config:serveModuleFunction:remove")
    @Log(title = "服务模块功能配置", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ecardServeModuleFunctionService.deleteEcardServeModuleFunctionByIds(ids));
    }
}
